package com.android.memoprendiz.model;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class ConfigurationsDAO {
	private Database dbManager;
	
	public ConfigurationsDAO(Context contexto){
		this.dbManager = new Database(contexto);
	}
	
	public Configuration getConfiguration(){
		SQLiteDatabase database = dbManager.getReadableDatabase(); 
		
		Cursor results = database.rawQuery("SELECT * FROM configuracao WHERE cod_config = 1;", null);
		results.moveToFirst();
		
		Configuration config = new Configuration(results.getString(1), results.getString(2));
		
		results.close();
		database.close();
	
		return config;
	}
	
	public void saveConfiguration(Configuration config){
		SQLiteDatabase database = dbManager.getWritableDatabase(); 
		database.execSQL("UPDATE configuracao SET " +
				"caminho_estilo = '" + config.getCaminhoEstilo() +
				"' , nivel_inicial = '" + config.getNivelInicial() +
				"' WHERE cod_config = 1");
			
		database.close();
	}	
}
